package com.cao.project.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cao.common.annotation.Log;
import com.cao.common.core.controller.BaseController;
import com.cao.common.core.domain.AjaxResult;
import com.cao.common.enums.BusinessType;
import com.cao.project.domain.ProjectNotification;
import com.cao.project.service.IProjectNotificationService;
import com.cao.common.utils.poi.ExcelUtil;
import com.cao.common.core.page.TableDataInfo;

/**
 * 通知Controller
 *
 * @author cao
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/project/notification")
public class ProjectNotificationController extends BaseController {
    @Autowired
    private IProjectNotificationService projectNotificationService;

    /**
     * 查询通知列表
     */
    @PreAuthorize("@ss.hasPermi('project:notification:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectNotification projectNotification) {
        startPage();
        List<ProjectNotification> list = projectNotificationService.selectProjectNotificationList(projectNotification);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('project:notification:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(ProjectNotification projectNotification) {
        List<ProjectNotification> list = projectNotificationService.selectProjectNotificationList(projectNotification);
        return success(list);
    }

    /**
     * 导出通知列表
     */
    @PreAuthorize("@ss.hasPermi('project:notification:export')")
    @Log(title = "通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectNotification projectNotification) {
        List<ProjectNotification> list = projectNotificationService.selectProjectNotificationList(projectNotification);
        ExcelUtil<ProjectNotification> util = new ExcelUtil<ProjectNotification>(ProjectNotification. class);
        util.exportExcel(response, list, "通知数据");
    }

    /**
     * 获取通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:notification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(projectNotificationService.getById(id));
    }

    /**
     * 新增通知
     */
    @PreAuthorize("@ss.hasPermi('project:notification:add')")
    @Log(title = "通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectNotification projectNotification) {
        return toAjax(projectNotificationService.save(projectNotification));
    }

    /**
     * 修改通知
     */
    @PreAuthorize("@ss.hasPermi('project:notification:edit')")
    @Log(title = "通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectNotification projectNotification) {
        return toAjax(projectNotificationService.updateById(projectNotification));
    }

    /**
     * 删除通知
     */
    @PreAuthorize("@ss.hasPermi('project:notification:remove')")
    @Log(title = "通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(projectNotificationService.removeByIds(Arrays.asList(ids)));
    }
}
